package com.zlfund.cat.zjgsmk.controller;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapShader;
import android.graphics.Paint;
import android.graphics.Shader;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.zlfund.cat.zjgsmk.R;
import com.zlfund.cat.zjgsmk.bean.UserBean;
import com.zlfund.cat.zjgsmk.option.GlideApp;
import com.zlfund.cat.zjgsmk.ui.base.ZApplication;
import com.zlfund.cat.zjgsmk.ui.user.UserManager;
import com.zlfund.cat.zjgsmk.util.BitmapHelper;
import com.zlfund.cat.zjgsmk.widget.RemindDialog;

/**
 * Created by chenj on 2017/9/21 0021.
 */

public class HasLoginHelper extends LoginStateImp {
    @Override
    public void showSquareUI(ViewGroup rootView) {
        super.showSquareUI(rootView);
        mLlFocusLlyt.setVisibility(View.VISIBLE);
    }

    @Override
    public void showSettingUI(ViewGroup rootView) {
        super.showSettingUI(rootView);
        final Context context = rootView.getContext();
        mLlLoginShow.setVisibility(View.VISIBLE);
        mTvLogin.setText("退出登录");
        mLlytLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new RemindDialog.Build(context)
                        .setMessage("是否退出登录")
                        .setOnSubmitListener(new RemindDialog.OnSubmitListener() {
                            @Override
                            public void onSubmit(View v) {
                                UserManager.exit();
                            }
                        })
                        .show();
            }
        });
    }

    @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN_MR1)
    @Override
    public void showUserUi(ViewGroup rootView, UserBean userBean) {
        super.showUserUi(rootView,userBean);
        mTvDesc.setVisibility(View.VISIBLE);
        mTvFans.setVisibility(View.VISIBLE);
        mTvFocus.setVisibility(View.VISIBLE);
        if (userBean == null) return;
        UserBean.RBean r = userBean.getR();
        if (r == null) return;
        String icoUrl = r.getIco() != null ? r.getIco() : r.getAvatar();
        GlideApp.with(ZApplication.mContext)
                .asBitmap()
                .load(icoUrl)
                .into(new SimpleTarget<Bitmap>() {
                    @Override
                    public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                        mHeadView.setBlurBm(resource);
                        mIvUserIcon.setImageBitmap(BitmapHelper.cropCircleImage(resource));
                    }
                });
        Paint paint = mTvName.getPaint();
        paint.setShader(new BitmapShader(BitmapFactory.decodeResource(ZApplication.mContext.getResources(),R.mipmap.tiaowen), Shader.TileMode.MIRROR, Shader.TileMode.MIRROR));
        mTvName.setLayerPaint(paint);
        mTvName.setText(r.getName());
        mTvDesc.setText(r.getBrief());
        mTvFans.setText("粉丝：" + r.getFansCount());
        mTvFocus.setText("关注：" + r.getFocusCount());
        mIvUserIcon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });
    }
}
